package com.transaction.service;

import com.transaction.dao.UserDao;
import com.transaction.handler.ThreadHandler;
import com.transaction.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Service
@Transactional
public class TestService {
    @Autowired
    private UserDao userDao;
    @Autowired
    private ThreadHandler threadHandler;
    public void testTransaction (){
        try{
            User user=new User();
//        testTransaction1();
            user.setUserphone("18255556666");
            user.setUsername("孔空空");
            user.setCreateDate(new Date());
            userDao.insert(user);
            threadHandler.testHandler();
            System.out.println("线程执行完毕");
        }catch (Exception e){
            e.printStackTrace();
            System.out.println("testService 异常");
        }
    }
//    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public void selectUser (){
        System.out.println("查询开始");
        User user=userDao.selectUser("孔空空");
        System.out.println(user.getId());
    }
}
